#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
    Point(int x = 0,int y = 0)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "Point(const Point &)" << endl;
    }

    Point & operator=(const Point & rhs){
        _ix = rhs._ix;
        _iy = rhs._iy;
        return *this;
    }

    void print() const{
             cout << "(" << this->_ix
            << "," << this->_iy
            << ")" << endl;
    }
private:
    int _ix;
    int _iy;
};

void test1(){
    int arr[3];
    cout << arr[0] << endl;

    Point pts[2];
    pts[0].print();
    pts[1].print();
}

void test2(){
    Point pt1(2,6);
    Point pt2(5,8);
    Point pts[2] = {pt1,pt2};
    Point pts1[2] = {Point(1, 2), Point(3, 4)};
    Point pts2[] = {Point(1, 2), Point(3, 4)};
    Point pts3[5] = {Point(1, 2), Point(3, 4)};
}

void test3(){
    Point pts[2] = {{1, 2}, {3, 4}};
    pts->print();  //（1,2）
    (pts + 1)->print(); //(3,4)
}

void test4(){
    Point * pt2 = new Point[5]();
    pt2->print();
	(pt2 + 1)->print();
    delete [] pt2;
    pt2 = nullptr;


    Point * pt3 = new Point[3]{{1,2},{6,7},{9,7}};
    pt3->print();
	(pt3 + 1)->print();
    delete [] pt3;
    pt3 = nullptr;
}

void test0(){
    Point pt(1, 2);
    /* Point pt2();//这不是无参的方式创建对象，而是函数的声明 */
    Point pt2;
    pt2.print();

    Point * p1 = nullptr;
    Point * p2 = &pt;
    Point * p3 = new Point(3, 4);
    delete p3;


    int * p = new int();
    delete p;

    //即使使用无参的方式创建堆空间上的对象
    //也最好加上小括号，确保完成初始化
    Point * p4 = new Point();
    p4->print();
    (*p4).print();
    delete p4;
}

int main(void){
    test4();
    return 0;
}
